var express = require('express');
var router = express.Router();
// var User = require('../models').User  // 就是 models/index.js导出的User
var models = require('../models')

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

// 注册接口
router.post('/register', function(req, res, next) {
  console.log(req.body)
  if(req.body.userName == null || req.body.pwd == null){
    return res.json({code: 100, msg: "用户信息不完整！"})
  }
  models.User.create(req.body).then(() => {
    return res.json({code:0,msg:"注册成功"})
  }).catch(() => {
    return res.json({code:100,msg:"注册失败"})
  })
  // User.create(req.body).then(() => {
  //   return res.json({code: 0, msg: "用户注册成功", users: {username: req.body.username}})
  // })
});

module.exports = router;
